
import 'package:get/get.dart';
import 'package:library_base/constant/constant.dart';
import 'package:library_base/entities/enum_entity.dart';
import 'package:library_base/ext/bool_ext.dart';
import 'package:library_base/global/multi_language.dart';
import 'package:library_base/utils/num_util.dart';
import 'package:library_base/utils/sp_util.dart';

extension StringExt on String{

    double strAsUnitNum(){
        double num = double.parse(this);
        return SPUtil.isJin? NumUtil.divide(num, 2):num;
    }

    double strAsUnitNum1(String sourceUnit){
        double num = double.parse(this);
        if(sourceUnit == ServiceUnit.JIN.name){
            if(SPUtil.isJin){
                return num;
            }else{
                return NumUtil.multiply(num, 2);
            }
        }else if(sourceUnit == ServiceUnit.KG.name){
            if(SPUtil.isJin){
                return NumUtil.divide(num, 2);
            }else{
                return num;
            }
        }else{
            if(SPUtil.isJin){
                return NumUtil.divide(num, 2);
            }else{
                return num;
            }
        }
    }


    getUnitStr() {
        if(this == ServiceUnit.JIN.name || this == ServiceUnit.KG.name){
            return SPUtil.isJin.unitStrZhWithYuan();
        }else if(this == ServiceUnit.FEN.name){
            return MultiLanguage.yuanFen.tr;
        }
        return '未知单位';
    }


}

